import java.io.Console;

public class ConsoleExample {
    public static void main(String[] args) {
        Console console = System.console();

        if (console == null) {
            System.out.println("控制台不可用（IDE里通常如此）");
            System.exit(1);
        }

        String name = console.readLine("请输入你的名字: ");
        char[] password = console.readPassword("请输入密码: ");

        System.out.println("你好，" + name);
        System.out.println("你输入的密码长度是：" + password.length);
    }
}